from flask import Flask, redirect, url_for, request, render_template, flash
import json, re

import _log

####################################################################################################

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/do_process', methods=['POST', 'GET'])
def do_process():
    if request.method == 'POST':
        try:
            val_date = request.form['date']
            val_weather   = request.form['weather']
            val_location  = request.form['location']
            val_person    = request.form['person']
            val_route     = request.form['route']
            val_content   = request.form['content']
        except Exception as e:
            _log.error('%s' % e)
            return 'get request.form fail!'

        ret_json = {
            'ret_str': val_date + ' ' + val_content.split('\n')[0] + '\n' + \
                       '\n' + \
                       '天气：' + val_weather + '\n' + \
                       '地点：' + val_location + '\n' + \
                       '人物：' + val_person + '\n' + \
                       '\n' + \
                       val_route + '\n' + \
                       '\n' + \
                       val_content
        }

        return json.dumps(ret_json)

    return 'invalid operation!'

if __name__ == '__main__':
    # 模块
    _log.init(app)

    # 网页
    app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'

    app.run(
        host='127.0.0.1',
        port= 5000,
        debug=True,
        threaded=True
    )
